// 控制侧边的logo和头部导航固定
import defaultSettings from '@/settings'
import { setTheme, getTheme } from '@/utils/auth'
const { showSettings, fixedHeader, sidebarLogo } = defaultSettings

const state = {
  showSettings: showSettings,
  fixedHeader: fixedHeader,
  sidebarLogo: sidebarLogo,
  theme: getTheme() || '#4b7cfb', // 颜色默认值
  themeKey: 'pig'
}

const mutations = {
  CHANGE_SETTING: (state, { key, value }) => {
    // eslint-disable-next-line no-prototype-builtins
    if (state.hasOwnProperty(key)) { // 判断对象中是否有你要修改的属性
      state[key] = value
    }
    // 只修改了theme属性后,做主题的存储
    if (key === 'theme') {
      setTheme(value)
    }
  }
  // 修改主题的mutation
  // changeTheme(state, val) {
  //   state.theme = val
  // }
}

const actions = {
  changeSetting({ commit }, data) {
    console.log(data)
    commit('CHANGE_SETTING', data)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

